import { promisifyAll } from 'miniprogram-api-promise'
import { getDropDownList } from './api/index'
import nav from './router/index'
const pro = {}
promisifyAll(wx, pro)
wx.$pro = pro
wx.$nav = nav
App({
  globalData: {
    form: {
      // companyName: '',
      // province: '',
      // city: '',
      // area: '',
      // detailAddress: '',
      // mobile: '',
      // companyMail: '',
      // companyUrl: '',
      // personsInChargeOfCompany: '',
      // personsInChargeOfCompanyPhoneAndMail: '',
      // saleInChargeOfCompany: '',
      // saleInChargeOfCompanyPhoneAndMail: '',
      // qualityInChargeOfCompany: '',
      // qualityInChargeOfCompanyPhoneAndMail: '',
      // headOfSales: '',
      // headOfSalesPhoneAndMail: '',
      // registeredFund: '',
      // companyCreateDate: '',
      // companyType: '',
      // generalTaxpayer: '',
      // supplierBrand: '',
      // productIntroduce: '',
      // productManualList: [],
      // productPositioning: '',
      // productTotalSale: '',
      // businessCoverage: '',
      // inDepartment: '',
      // partyABrand: [''],
      // partyACollection: [''],
      // constructionBrand: [''],
      // constructionCollection: [''],
      // deliveryDay: '',
      // needBilling: true,
      // customerList: [{
      //   customerName: '',
      //   specification: '',
      //   annualOrderAmount: ''
      // }],
      // totalEmployees: '',
      // management: '',
      // technician: '',
      // worker: '',
      // fixedAssets: '',
      // materialOriginal: '',
      // materialOriginal: '',
      // importedEquipmentNumber: '',
      // domesticNumber: '',
      // otherInformation: '',
      // annualProductionCapacity: '',
      // researchProductivity: '',
      // authentication: [''],
      // fileCompleted: '',
      // inspectionOrganizationName: '',
      // supplierQualificationNumber: '',
      // qualityTotalEquipmentNumber: '',
      // qualityImportedEquipmentNumber: '',
      // qualitySelfMadeEquipment: '',
      // qualityDomesticNumber: '',
      // qualityOtherInformation: '',
      // passedQualityCertification: '',
      // passedHealthCertification: '',
      // passedEnvironmentCertification: '',
      // certificationFileIds: [],
      // healthCertificationFileIds: [],
      // environmentCertificationFileIds: [],
      // businessLicenseFileIds: [],
      // proxyCertificateFileIds: [],
      // companyFileIds: []
    },
    dropDown: {
      generalTaxpayerList: [],
      productPositioningList: [],
      inDepartmentList: [],
      needBillingList: [],
      researchProductivityList: [],
      fileCompletedList: [],
      certificationList: [],
      dicTypeName: [],
      dicTypeValueId: [],
      companyTypeList: []
    },
    getDropDownCallback: null,
    systemInfo: {}
  },
  getSystemInfo () {
    const { windowHeight, screenHeight, pixelRatio, statusBarHeight } = wx.getSystemInfoSync()
    this.globalData.systemInfo.windowHeight = windowHeight
    this.globalData.systemInfo.screenHeight = screenHeight
    this.globalData.systemInfo.pixelRatio = pixelRatio
    this.globalData.systemInfo.statusBarHeight = statusBarHeight
  },
  async getDropDownList () {
    try {
      const { ResultSet } = await getDropDownList()
      this.globalData.dropDown = ResultSet.userData
      if (this.globalData.getDropDownCallback) this.globalData.getDropDownCallback()
    } catch (err) {
      wx.showToast({ title: err.message || err.ResultSet.errors, icon: 'none' })
    }
  },
  onLaunch() {
    this.getDropDownList()
  },
  onHide () {},
  onUnhandledRejection ({reason}) {
    if (reason.errMsg.indexOf('system deny') !== -1) wx.showToast({ title: '操作失败，请在设置中打开微信权限', icon: 'none' })
  }
})
